package com.studies.pc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studies.pc.pojo.Activity;
import com.studies.pc.pojo.ActivityRecord;
import com.studies.pc.mapper.ActivityRecordMapper;
import com.studies.pc.query.ActivityRecordQuery;
import com.studies.pc.service.ActivityRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 研学风采 服务实现类
 * </p>
 *
 * @author 研学活动后台
 * @since 2019-12-24
 */
@Service
public class ActivityRecordServiceImpl extends ServiceImpl<ActivityRecordMapper, ActivityRecord> implements ActivityRecordService {
    //首页研学风采分页实现
    @Override
    public Map<String, Object> selectRecordPage(Page<ActivityRecord> pageParam, ActivityRecordQuery activityRecordQuery) {
        QueryWrapper<ActivityRecord> queryWrapper =new QueryWrapper<>();
        queryWrapper.orderByDesc("update_time");
        if (activityRecordQuery.getActivityId()!=null){
            queryWrapper.eq("activity_id",activityRecordQuery.getActivityId());
        }
        if (activityRecordQuery.getSchyearTerm()!=null){
            queryWrapper.like("schyear_term",activityRecordQuery.getSchyearTerm());
        }
        if (activityRecordQuery.getType()!=null){
            queryWrapper.eq("type",activityRecordQuery.getType());
        }
        baseMapper.selectPage(pageParam,queryWrapper);
        List<ActivityRecord> records =pageParam.getRecords();
        long current = pageParam.getCurrent();
        long pages = pageParam.getPages();
        long size = pageParam.getSize();
        long total = pageParam.getTotal();
        boolean hasNext = pageParam.hasNext();
        boolean hasPrevious = pageParam.hasPrevious();


        Map<String, Object> map = new HashMap<String, Object>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}
